package com.hnote.hnoteapplication.ui.activity;


import android.content.Intent;

import com.hnote.hnoteapplication.R;
import com.hnote.hnoteapplication.base.DataBindingActivity;
import com.hnote.hnoteapplication.databinding.ActivitySnowBinding;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;

/**
 * =====================================================
 * 功    能： 启动页
 * 作    者： 加菲猫
 * 邮    箱： pfliu@3box.cc
 * 时    间： 2017/3/8 0008 14:45
 * =====================================================
 */
public class SnowActivity extends DataBindingActivity<ActivitySnowBinding>{

    @Override
    public int getLayoutId() {
        return R.layout.activity_snow;
    }

    @Override
    public void initView() {

        int countTime = 5;

        subscription = Observable.interval(0, 1, TimeUnit.SECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .map((increaseTime) -> countTime - increaseTime.intValue())
                .take(countTime + 1)
                .doOnSubscribe(() -> { }) // 开始计时
                .subscribe(new Subscriber<Integer>() {
                    @Override
                    public void onCompleted() {
                        // 计时完成
                        startActivity(new Intent(SnowActivity.this, MainActivity.class));
                        finish();
                        overridePendingTransition(R.anim.in_from_right,R.anim.out_to_left);
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Integer integer) {
                        // 当前计时
                    }
                });

//        subscription = Observable.interval(0, 1, TimeUnit.SECONDS)
//                .subscribeOn(AndroidSchedulers.mainThread())
//                .observeOn(AndroidSchedulers.mainThread())
//                .map(new Func1<Long, Integer>() {
//                    @Override
//                    public Integer call(Long increaseTime) {
//                        return countTime - increaseTime.intValue();
//                    }
//                })
//                .take(countTime + 1)
//                .doOnSubscribe(new Action0() {
//                    @Override
//                    public void call() {
//                        // 开始计时
//                    }
//                })
//                .subscribe(new Subscriber<Integer>() {
//                    @Override
//                    public void onCompleted() {
//                        // 计时完成
//                        startActivity(new Intent(SnowActivity.this, MainActivity.class));
//                        finish();
//                        overridePendingTransition(R.anim.in_from_right,R.anim.out_to_left);
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//
//                    }
//
//                    @Override
//                    public void onNext(Integer integer) {
//                       // 当前计时
//                    }
//                });
    }

}
